// 注册
const onregister = function () {
    let regist = document.querySelector(".register")
    let usernameInput = document.querySelector('input[name="username"]')
    let passwordInput = document.querySelector('input[name="password"]')
    let headerImgInput=document.querySelector('input[name="headerImg"]')//头像
    let nickInput=document.querySelector('input[name="nick"]') //昵称
    let againPasswordInput = document.querySelector('input[name="again-password"]')

    regist.addEventListener('submit', function (e) {
        e = e || window.event
        e.preventDefault()

        let username = usernameInput.value
        let password = passwordInput.value
        let again_password = againPasswordInput.value
        let nick = nickInput.value
		let headerImgFile = headerImgInput.files[0] 

        if (username == "" ||password == ""|| again_password == ""||password !== again_password||nick==""||headerImgFile=="") 
        {alert('您输入的信息有误或者不完整')}
        else{
            myPromise({
                method: 'post',
                url: "https://api.yuguoxy.com/api/member/add",
                data: {
                    username,
                    password,
                    nick,
                    headerImgFile
                }
            }).then(res => {
                console.log(res)
              if(res.resultCode==-1){
                alert("用户已注册")
              }
              else if(res.resultCode==1)
              {
                alert("注册成功")
              }
                
            }).catch(err => {
                alert(err)
            })
        }

   


})


}

onregister()